<?php
class pro_permintaan_pembayaran_model  extends MY_Model {
	var $model = 'pro_permintaan_pembayaran';
	
	function GetJSON()
	{
		$ls_sql	= "	SELECT	no_pembayaran,id_pembayaran,
							TO_CHAR(tanggal_bayar,'DD/MM/YYYY') tanggal_bayar,
							keterangan
					FROM	pro_permintaan_pembayaran
					WHERE	(UPPER(id_pembayaran) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(tanggal_bayar) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(keterangan) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_pembayaran) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'id_pembayaran' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
		return json_encode( $this->paging($ls_sql) );
	}

	function GetJSONdetail($id){
		$ls_sql	= "	SELECT	id_pembayaran,id_pembayaran_detail,
							harga_satuan,banyak_satuan,total,
							keterangan_uraian
					FROM	pro_permintaan_pembayaran_dtl
					WHERE	id_pembayaran = '$id' AND (UPPER(id_pembayaran) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(harga_satuan) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(total) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(keterangan_uraian) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'id_pembayaran_detail' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
		return json_encode( $this->paging($ls_sql) );
	}
		
	function Add($arr_data){
		$this->db->insert('pro_permintaan_pembayaran', $arr_data);
	}
	
	function Update($arr_data, $arr_rule){
		$this->db->update('pro_permintaan_pembayaran', $arr_data, $arr_rule);
	}
	
	function GetSingle($as_id_pembayaran){
		$result = $this->db->query("SELECT	no_pembayaran,id_pembayaran,
									TO_CHAR(tanggal_bayar,'DD/MM/YYYY') tanggal_bayar,
									keterangan
							FROM	pro_permintaan_pembayaran
							WHERE id_pembayaran = '$as_id_pembayaran' ");
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	function GetSingleView($as_id_pembayaran)
	{
		$result = $this->db->query("SELECT	no_pembayaran,id_pembayaran,
									TO_CHAR(tanggal_bayar,'DD/MM/YYYY') tanggal_bayar,
									keterangan
							FROM	pro_permintaan_pembayaran
							WHERE id_pembayaran = '$as_id_pembayaran'");
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}

	function DeleteSingle($arr_rule)
	{
		try {
			if(	intval($this->get_data("SELECT COUNT(1) FROM pro_permintaan_pembayaran WHERE id_pembayaran= '".$arr_rule['id_pembayaran']."'"))<=0)
			{
				return $this->error_delete.' [id: '.$arr_rule['id_pembayaran']."]<br />";
			}else{
				$this->db->delete('pro_permintaan_pembayaran', array('id_pembayaran' => $arr_rule['id_pembayaran']));
				return '';
			}
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}

	function GetCetak($as_no_pembayaran)
	{
		$result1 = $this->db->query(" 	SELECT	*
										FROM	pro_permintaan_pembayaran
										WHERE	no_pembayaran = '$as_no_pembayaran' ");
		return $result1->row_array();
		
	}
}
?>